package ink.lovejinhu.leetcode;

import ink.lovejinhu.common.TreeNode;

/**
 * @author jinhu
 * created 2021-07-07 11:31
 */
public class Solution_0266 {
    /**
     * 翻转二叉树
     *
     * @param root
     * @return
     */
    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }

        /**
         * 交换左子树的值和右子树的值
         */
        TreeNode temp = null;
        temp = root.left;
        root.left = root.right;
        root.right = temp;
        //递归交换子树
        invertTree(root.left);
        invertTree(root.right);


        return root;

    }
}
